''' Hid.py
	
	Windows HID interface
	
	
   Copyright 2008 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
'''

import win32con
import sys
from ctypes import *
from ctypes.wintypes import * 

DIGCF_DEFAULT			= 0x00000001
DIGCF_PRESENT			= 0x00000002
DIGCF_ALLCLASSES		= 0x00000004
DIGCF_PROFILE			= 0x00000008
DIGCF_DEVICEINTERFACE	= 0x00000010

class EFileAttributes(object):
	Readonly         = 0x00000001
	Hidden           = 0x00000002
	System           = 0x00000004
	Directory        = 0x00000010
	Archive          = 0x00000020
	Device           = 0x00000040
	Normal           = 0x00000080
	Temporary        = 0x00000100
	SparseFile       = 0x00000200
	ReparsePoint     = 0x00000400
	Compressed       = 0x00000800
	Offline          = 0x00001000
	NotContentIndexed= 0x00002000
	Encrypted        = 0x00004000
	Write_Through    = 0x80000000
	Overlapped       = 0x40000000
	NoBuffering      = 0x20000000
	RandomAccess     = 0x10000000
	SequentialScan   = 0x08000000
	DeleteOnClose    = 0x04000000
	BackupSemantics  = 0x02000000
	PosixSemantics   = 0x01000000
	OpenReparsePoint = 0x00200000
	OpenNoRecall     = 0x00100000
	FirstPipeInstance= 0x00080000

Guid = c_char * 16

class SP_DEVINFO_DATA(Structure):
	_fields_ = [
		('cbSize', c_uint),
		('ClassGuid', Guid),
		('DevInst', c_uint),
		('Reserved', POINTER(c_int))
	]

class SP_DEVICE_INTERFACE_DATA(Structure):
	_fields_ = [
		('cbSize', c_int),
		('InterfaceClassGuid', Guid),
		('Flags', c_int),
		('RESERVED', POINTER(c_int))
	]

class SP_DEVICE_INTERFACE_DETAIL_DATA(Structure):
	_pack_ = 1
	_fields_ = [
		('cbSize', c_uint32),
		('DevicePath', c_char * 256)
	]

class HIDD_ATTRIBUTES(Structure):
	_fields_ = [
		('Size', c_int),
		('VendorID', c_short),
		('ProductID', c_short),
		('VersionNumber', c_short)
	]

HidD_GetHidGuid = windll.hid.HidD_GetHidGuid
HidD_GetHidGuid.argtypes = [ POINTER(Guid) ]

HidD_GetAttributes = windll.hid.HidD_GetAttributes
HidD_GetAttributes.argtypes = [ HANDLE, POINTER(HIDD_ATTRIBUTES) ]
HidD_GetAttributes.restype = BOOLEAN

HidD_SetOutputReport = windll.hid.HidD_SetOutputReport
HidD_SetOutputReport.argtypes = [ HANDLE, c_void_p, ULONG ]
HidD_SetOutputReport.restype = BOOLEAN

SetupDiGetClassDevs = windll.setupapi.SetupDiGetClassDevsA
SetupDiGetClassDevs.argtypes = [ POINTER(Guid), c_char_p, HWND, DWORD ]
SetupDiGetClassDevs.restype = HANDLE

SetupDiEnumDeviceInterfaces = windll.setupapi.SetupDiEnumDeviceInterfaces
SetupDiEnumDeviceInterfaces.argtypes = [ HANDLE, c_void_p, POINTER(Guid),
	c_int, POINTER(SP_DEVICE_INTERFACE_DATA) ]
SetupDiEnumDeviceInterfaces.restype = BOOL

SetupDiGetDeviceInterfaceDetail = windll.setupapi.SetupDiGetDeviceInterfaceDetailA
SetupDiGetDeviceInterfaceDetail.argtypes = [ HANDLE, POINTER(SP_DEVICE_INTERFACE_DATA),
	c_void_p, c_uint, POINTER(DWORD), c_void_p ]
SetupDiGetDeviceInterfaceDetail.restype = BOOL

SetupDiDestroyDeviceInfoList = windll.setupapi.SetupDiDestroyDeviceInfoList
SetupDiDestroyDeviceInfoList.argtypes = [ HANDLE ]
SetupDiDestroyDeviceInfoList.restype = BOOL

